﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using System.ComponentModel;
using System.Web;

namespace Skynet.WebAdministracion.Views.StartExamViewer
{
    [System.ComponentModel.DataObject]
    public class StartExamViewerPresenter : Infrastructure.Web.Views.Master.MasterPresenter<IStartExamViewerView>
    {
        [Dependency]
        public WebFoundation.Services.Session.ISessionService SessionService { get; set; }

        [Dependency]
        public WebFoundation.Services.Navigation.INavigationService NavigationService { get; set; }


        [Dependency]
        public BusinessLogic.BusinessComponents.IBCExams BCExamenes { get; set; }


        [Dependency]
        public BusinessLogic.BusinessComponents.IBCCustomers BCCustomers { get; set; }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public object GetActiveExams(Guid ExamByCustomerId)
        {
            var userName = HttpContext.Current.User.Identity.Name;
            var customer = this.BCCustomers.SearchCustomers(option: BusinessLogic.BusinessComponents.CustomerSearchOption.GetByUserName, UserName: userName).SingleOrDefault();
            var exams = BCExamenes.SearchExamByCustomer(options: BusinessLogic.BusinessComponents.ExamByCustomerSearchOptions.GetByCustomerIdLoadExamExamCategory, CustomerId: customer.Id);
            var query = (from c in exams where c.Id == ExamByCustomerId select new { Id = c.Id, Category = c.Exam.ExamCategory.Title, Title = c.Exam.Title, Duration = c.Duration, ValidFrom = c.ValidFrom, ValidTo = c.ValidTo }).SingleOrDefault();
            return query;
        }

        public void AcceptExam(Guid key)
        {
            this.SessionService.ExamByCustomerId = key;            
            this.BCExamenes.AcceptExam(key);
            this.SessionService.RuntimeExamByCustomerId = key; 
            //this.SessionService.RuntimeExamQuestions =  this.BCExamenes.AcceptExam
        }
    }
}
